package com.gitee.chili.leisure.service.impl;

import com.gitee.chili.leisure.domain.Currency;
import com.gitee.chili.leisure.enums.CurrencyToken;
import com.gitee.chili.leisure.repository.CurrencyRepository;
import com.gitee.chili.leisure.service.ICurrencyService;
import com.gitee.chili.leisure.util.Enum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * CurrencyService
 *
 * @author week solider
 * @since 2020.09.01
 */
@Service
public class CurrencyService implements ICurrencyService {

    @Autowired
    private CurrencyRepository currencyRepository;

    @Override
    public CurrencyRepository getRepository() {
        return currencyRepository;
    }

    @Override
    public Currency getCurrency(Integer tokenValue) {

        CurrencyToken token = Enum.valueOf(CurrencyToken.class, t -> t.getCode().equals(tokenValue));
        return currencyRepository.findByToken(token);
    }
}
